package com.yytek.nmp.service.impl;

import java.util.List;

import cn.hutool.core.collection.CollectionUtil;
import com.yytek.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yytek.nmp.mapper.IotModelDefineMapper;
import com.yytek.nmp.domain.IotModelDefine;
import com.yytek.nmp.service.IIotModelDefineService;

/**
 * 物模型定义Service业务层处理
 * 
 * @author yytek-iot
 * @date 2022-07-05
 */
@Service
public class IotModelDefineServiceImpl implements IIotModelDefineService
{
    @Autowired
    private IotModelDefineMapper iotModelDefineMapper;

    /**
     * 查询物模型定义
     * 
     * @param id 物模型定义主键
     * @return 物模型定义
     */
    @Override
    public IotModelDefine selectIotModelDefineById(Long id)
    {
        return iotModelDefineMapper.selectIotModelDefineById(id);
    }

    /**
     * 查询物模型定义列表
     * 
     * @param iotModelDefine 物模型定义
     * @return 物模型定义
     */
    @Override
    public List<IotModelDefine> selectIotModelDefineList(IotModelDefine iotModelDefine)
    {
        return iotModelDefineMapper.selectIotModelDefineList(iotModelDefine);
    }

    /**
     * 新增物模型定义
     * 
     * @param iotModelDefine 物模型定义
     * @return 结果
     */
    @Override
    public int insertIotModelDefine(IotModelDefine iotModelDefine)
    {
        iotModelDefine.setCreateTime(DateUtils.getNowDate());
        return iotModelDefineMapper.insertIotModelDefine(iotModelDefine);
    }

    /**
     * 修改物模型定义
     * 
     * @param iotModelDefine 物模型定义
     * @return 结果
     */
    @Override
    public int updateIotModelDefine(IotModelDefine iotModelDefine)
    {
        iotModelDefine.setUpdateTime(DateUtils.getNowDate());
        return iotModelDefineMapper.updateIotModelDefine(iotModelDefine);
    }

    /**
     * 批量删除物模型定义
     * 
     * @param ids 需要删除的物模型定义主键
     * @return 结果
     */
    @Override
    public int deleteIotModelDefineByIds(Long[] ids)
    {
        return iotModelDefineMapper.deleteIotModelDefineByIds(ids);
    }

    /**
     * 删除物模型定义信息
     * 
     * @param id 物模型定义主键
     * @return 结果
     */
    @Override
    public int deleteIotModelDefineById(Long id)
    {
        return iotModelDefineMapper.deleteIotModelDefineById(id);
    }

    @Override
    public boolean exeitByName(String modelName) {
        List<IotModelDefine>  reList = iotModelDefineMapper.selectIotModelDefineByName(modelName,null);
        if(CollectionUtil.isNotEmpty(reList)){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public boolean exeitByNameAndNoId(String modelName, Long id) {
        List<IotModelDefine>  reList = iotModelDefineMapper.selectIotModelDefineByName(modelName,id);
        if(CollectionUtil.isNotEmpty(reList)){
            return true;
        }else {
            return false;
        }
    }

    /**
     * 根据设备Id查询物模型信息
     * @param iotId
     * @return
     */
    @Override
    public IotModelDefine getDeviceModelByIotId(String iotId) {
        IotModelDefine modelDefine = iotModelDefineMapper.getDeviceModelByIotId(iotId);
        return modelDefine;
    }
}
